Ext.define('App.main.view.Viewport', {
    extend: 'Ext.tab.Panel',
    alias: ['widget.Viewport'],
    requires: ['App.datacollection.collectioninterface.view.CollectionInterfaceList',
        'App.datacollection.collectiontask.view.CollectionTaskList',
        'App.datacollection.taskinstance.view.TaskInstanceList',
        'App.datacollection.collectionschedule.view.CollectionScheduleList'],
    stateful: true,
    stateId: 'Viewport',
    stateEvents: ["tabchange"],
    getState: function () {
        var state = this.callParent();
        state.activeTabxx = this.getActiveTab().id;
        return state;
    },
    listeners: {
        afterrender: function () {
            this.setActiveTab(this.activeTabxx)
        }
    },
    items: [{
        xtype: 'CollectionInterfaceList',
        id: "CollectionInterfaceList_all",
        title: '采集接口'/*,
        extraParams: function () {
            return {'params.project.id_eq': (!Ext.isEmpty(app.project)) ? app.project.id : ''}
        }*/
    }, {
        xtype: 'CollectionTaskList',
        id: "CollectionTaskList_all",
        title: '采集任务'/*,
        extraParams: function () {
            return {'params.project.id_eq': (!Ext.isEmpty(app.project)) ? app.project.id : ''}
        }*/
    }, {
        xtype: 'CollectionScheduleList',
        id: "CollectionScheduleList_all",
        title: '采集计划'/*,
        extraParams: function () {
            return {'params.project.id_eq': (!Ext.isEmpty(app.project)) ? app.project.id : ''}
        }*/
    }, {
        xtype: 'TaskInstanceList',
        title: '运行中',
        id: "TaskInstanceList_runing",
        extraParams: function () {
            return {'params.status_in': [1, 2]}
        },
        tbar: {
            stop: {
                text: "停止",
                handler: function () {
                    var me = this.up('CrudGridPanel');
                    me.stopHandler.call(me);
                }
            }
        },
        stopHandler: function () {
            var me = this;
            var selection = me.getSelectionModel().getSelection();
            if (selection.length > 0) {
                var data = selection[0].data;
                Ext.Ajax.request({
                    url: 'datacollection/collectionschedule/stop_job',
                    params: {
                        taskInstanceId: data.id
                    },
                    success: function (resp) {
                        try {
                            if (resp.result.success) {
                                Extend.Msg.info("提示", resp.result.result)
                                me.reload();
                            }
                        } finally {
                            me.unmask();
                        }
                    },
                    failure: function () {
                        me.unmask();
                    }
                });
            }
        }
    }, {
        xtype: 'TaskInstanceList',
        title: '已完成',
        id: "TaskInstanceList_finished",
        extraParams: function () {
            return {'params.status_notin': [1, 2]}
        }
    }
    ]
})
;